package com.example.farm.controller;


import com.example.farm.Bean.UserData;
import com.example.farm.service.UserDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 姚
 * @since 2023-04-15
 */
@RestController
@RequestMapping("/userdata")
public class UserDataController {

    @Autowired
    private UserDataService userDataService;

    //更新用户信息
    @RequestMapping(value = "/update",produces = "application/json;charset=UTF-8")
    public int updateUserData(@RequestBody(required = false) UserData userData){
        return userDataService.insertUserData(userData);
    }

    //查询用户信息
    @RequestMapping(value = "/select",produces = "application/json;charset=UTF-8")
    public Object select(@RequestBody(required = false) String name){
        return userDataService.selectUserData(name);
    }


    //注册
    @RequestMapping(value = "/register" ,produces = "application/json;charset=UTF-8" )
    public int register(@RequestBody(required = false) UserData userData){
        System.out.println(userData);
        return userDataService.register(userData);
    }

    //登录
    @RequestMapping(value = "/login"   ,produces = "application/json;charset=UTF-8")
    public int login(@RequestBody(required = false) UserData userData){
        System.out.println(userData);

        System.out.println("-----------------"+userDataService.login(userData));
        return userDataService.login(userData);
    }


}

